<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
<style>
    #yearaudit_takecaruser_button{
        display: flex;
        justify-content: center;
        margin-top: 2%;
    }
</style>
<!-- 工具栏 -->
<script type="text/html" id="toolbarYearauditTakecaruser">
    <div class="layui-input-inline">
        <label >姓名:</label>
    </div>
    <div class="layui-input-inline">
        <input class="layui-input" id="nickname" placeholder="姓名" autocomplete="off" />
    </div>
    <div class="layui-input-inline">
        <label >电话:</label>
    </div>
    <div class="layui-input-inline">
        <input class="layui-input" id="phone" placeholder="电话" autocomplete="off" />
    </div>
    <button class="layui-btn layui-btn-normal" id="search" data-type="reload">搜索</button>
</script>
<body>
<input id="orderId" th:value="${orderId}" hidden>
<div class="layui-fluid">
    <div style="margin-top: 5px">
        <div class="layui-input-inline">
            <label >当前订单取车人:</label>
        </div>
        <div class="layui-input-inline">
            <input type="text" id="takecaruser" th:value="${takecaruser}" disabled  class="layui-input">
        </div>
    </div>
    <table id="yearaudit_takecaruser-table" lay-filter="yearaudit_takecaruser-table"></table>
    <div id="yearaudit_takecaruser_button">
        <button type="button" class="layui-btn" id="save">保存</button>
        <button type="button" class="layui-btn" id="cancel">取消</button>
    </div>
</div>
<script th:replace="/common/template :: script"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['layer', 'jquery', 'form','table' ,'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        // 渲染表格
        var renderTable = function () {
            layer.load(2);
            table.render({
                elem: '#yearaudit_takecaruser-table',
                url: '/yearaudit/order/takecaruserList',
                toolbar: '#toolbarYearauditTakecaruser',
                defaultToolbar: [],
                page: true,
                id: 'yearauditOrderReload',
                height: 'full-120',
                limit : 5,
                parseData: chaoLayuiTable.parseData,
                request: chaoLayuiTable.request,
                response: chaoLayuiTable.response,
                cols: [[{
                    type: 'radio',
                    fixed: 'left'
                },
                    {
                        width: 80,
                        type: 'numbers',
                        align: 'center',
                        title: '序号',
                    },
                    {
                        align: 'center',
                        field: 'nickname',
                        title: '姓名',

                    },
                    {
                        align: 'center',
                        field: 'phone',
                        title: '手机号',
                    }
                ]
                ],
                done: function () {
                    layer.closeAll('loading');
                }
            });

        };
        renderTable();

        table.on('radio(yearaudit_takecaruser-table)', function(obj){
            console.log(obj.checked); //当前是否选中状态
            console.log(obj.data); //选中行的相关数据
            if(obj.checked==true){
                var nickname = obj.data.nickname;
                $("#takecaruser").val(nickname);

            }
        });

        var active = {
            reload : function() {
                //执行重载
                table.reload('yearauditOrderReload', {
                    page : {
                        curr : 1
                        //重新从第 1 页开始
                    },
                    where : {
                        nickname: $("#nickname").val(),
                        phone: $("#phone").val()
                    }
                });
            }
        };

        /**解决工具栏按钮表格重载后无效的问题**/
        $('body').on('click', '#search', function() {
            // xxxxx
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        })

        $("#save").click(function (){
            var checkStatus = table.checkStatus("yearauditOrderReload");
            var checkData = checkStatus.data;
            var data = {};
            data.orderId = $("#orderId").val();
            if(!checkData[0].nickname){
                layer.msg("请完善取车人信息");
                return false;
            }
            data.userId = checkData[0].id;
            CoreUtil.ajaxPostLoad("/yearaudit/order/saveOrderTakecaruser", data,true,parent.active);
        })

        $("#cancel").click(function (){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index);
        })
    });
</script>
</body>
</html>